Kotlin
Nested and Inner Classes
Swift
|
class Outer {
private val bar: Int = 1
class Nested {
fun foo() = 2
}
}
val demo = Outer.Nested().foo() // == 2
|
class Outer {
private let bar: Int = 1
class Nested {
func foo() = 2
}
}
let demo = Outer.Nested().foo() // == 2
|
interface OuterInterface {
class InnerClass
interface InnerInterface
}
class OuterClass {
class InnerClass
interface InnerInterface
}
|
interface OuterInterface {
class InnerClass
interface InnerInterface
}
class OuterClass {
class InnerClass
interface InnerInterface
}
|
Inner classes
|
class Outer {
private val bar: Int = 1
inner class Inner {
fun foo() = bar
}
}
val demo = Outer().Inner().foo() // == 1
|
class Outer {
private let bar: Int = 1
inner class Inner {
func foo() = bar
}
}
let demo = Outer().Inner().foo() // == 1
|
Anonymous inner classes
|
window.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) { ... }
override fun mouseEntered(e: MouseEvent) { ... }
})
|
window.addMouseListener(object : MouseAdapter() {
override func mouseClicked(e: MouseEvent) { ... }
override func mouseEntered(e: MouseEvent) { ... }
})
|
val listener = ActionListener { println("clicked") }
|
let listener = ActionListener { print("clicked") }
|